package com.example.jetpackpaging.adapter

import android.graphics.Color
import android.text.TextUtils
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.example.jetpackpaging.R
import com.squareup.picasso.Picasso

/**
 * 图片适配器，需要使用@BindingAdapter注解来注释，
 */
class ImageViewBindingAdapter {

    companion object{

        @JvmStatic
        @BindingAdapter("image")
        fun setImage(imageView: ImageView,url: String){
            if(!TextUtils.isEmpty(url)){
                Picasso.get().load(url).placeholder(R.drawable.ic_launcher_background).into(imageView)
            }else{
                imageView.setBackgroundColor(Color.GRAY)
            }
        }
    }

}